<template>
  <div>
    <input type="text" v-if="showInput" ref="inp" />
    <button @click="handleShow">点击搜索</button>
    <h1 ref="h1">{{ msg }}</h1>
  </div>
</template>

<script>
export default {
  data() {
    return {
      showInput: false,
      msg: '你好',
    }
  },
  methods: {
    handleShow() {
      this.showInput = true
      this.msg = '我不好'
      console.log(this.$refs.h1.innerHTML)
      this.$nextTick(() => {
        this.$refs.inp.focus()
        console.log(this.$refs.h1.innerHTML)
      })
    },
  },
}
</script>

<style scoped></style>
